﻿@using Gantt.Options
@using Microsoft.Extensions.Options
@using RuoVea.ExDto
@inject IOptionsMonitor<SystemInfo> systemInfo;
@inject ICurrentUser _currentUser
@{
    bool isAdmin = User?.Claims.Any(c => c.Type == ClaimConst.CLAINM_ISADMIN && c.Value == "true") ?? false;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@systemInfo.CurrentValue.Title</title>
    <link href="~/elementui/index.min.css?v=1" rel="stylesheet" asp-append-version="true" />
    <style type="text/css"> .el-menu-item i,.el-submenu i { color: @systemInfo.CurrentValue.SkinColor } .el-menu--horizontal > .el-menu-item.is-active {color: @systemInfo.CurrentValue.SkinColor !important;} </style>
</head>
<body>
    <div id="main" v-cloak>
        <el-extend-header class="elmy" logo-src="/img/logo.png" logo-title="@systemInfo.CurrentValue.Title" :menu-data="menuData" :active-index="activeIndex" user-name="@_currentUser.Name" user-avatar="" :select="handleSelect"
                          login-out-txt="退出登录" :handle-logout="logout"></el-extend-header>
        <el-main><iframe ref="iframe" :src="activeIndex" style="width:100%;"></iframe></el-main>
    </div>
    <script src="~/vue/vue.js"></script>
    <script src="~/elementui/index.min.js?v=11"></script>
    <script>Vue.prototype.$baseURL = "";</script>
    <script src="~/vue/axios.min.min.js"></script>
    <script src="~/vue/vue-i18n.min.js"></script>
    <script>
        var $taskVue = new Vue({
            el: "#main",
            data() {
                return {
                    isAdmin: @(isAdmin.ToString().ToLower()),
                    menuData: [],
                    activeIndex: "",
                    defultIndex: "",
                }
            },
            created() {
                if (this.isAdmin) {
                    this.menuData = [
                        { title: "用户管理", path: "/user/index", icon: 'el-icon-user' },
                        { title: "系统设置", path: "/config/index", icon: 'el-icon-setting' },
                        {
                            title: "日志记录", path: "/log", icon: 'el-icon-date',
                            children: [
                                { title: "差异日志", path: "/logdiff/index", icon: 'el-icon-edit' },
                                { title: "异常日志", path: "/logex/index", icon: 'el-icon-notebook-1' },
                                { title: "操作日志", path: "/logop/index", icon: 'el-icon-document' },
                                { title: "访问日志", path: "/logvis/index", icon: 'el-icon-tickets' }],
                        },

                    ];
                    this.defultIndex = "/user/index";
                    this.activeIndex = this.defultIndex;
                }
                else {
                    this.menuData = [
                        { title: "项目计划", path: "/gantt", icon: 'el-icon-chat-line-square' },
                        { title: "项目管理", path: "/project", icon: 'el-icon-postcard' },
                    ]; 
                    this.defultIndex = "/gantt";
                    this.activeIndex = this.defultIndex;
                }
            },
            methods: {
                adjustIframeHeight() {
                    const iframe = this.$refs.iframe;
                    if (iframe) {
                        const newHeight = window.innerHeight - 125;
                        iframe.style.minHeight = `${newHeight}px`;
                        iframe.style.border = 'none';
                    }
                },
                handleSelect(key, keyPath) {
                    if (key) {
                        this.activeIndex = key;
                    } else {
                        this.activeIndex = this.defultIndex;
                    }
                },
                logout() {
                    console.log('Logging out...');
                    window.location.href = "/auth/logout";
                },
            },
            mounted() {
                this.adjustIframeHeight();
                window.addEventListener('resize', this.adjustIframeHeight);
            },
            beforeDestroy() {
                window.removeEventListener('resize', this.adjustIframeHeight);
            },
        });
    </script>
</body>
</html>
